<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <input type="text" placeholder="输入一个数" id="number">
    <button id="btn">点我插入</button>
    <div id="content"></div>
    <script>
        var arr=[0,10,20,30,40]
        content.innerText=arr;
        btn.onclick=function(){
            var n=Number(number.value);
            console.log(n);
            for(var i=0;i<arr.length;i++)
            {
                if(n<arr[i])
                {
                    var j;
                    for(j=arr.length;j>i;j--)
                    {
                        arr[j]=arr[j-1]
                    }
                    arr[j]=n; 
                   content.innerText=arr;
                    return arr;
                } 
            }
             if (n>=arr[arr.length-1])
             {
                 arr.push(n);
                 content.innerText=arr;
             }
             else
             {
                 arr.unshift(n)
                 content.innerText=arr;
             }
             
        }
        
    </script>
</body>
</html>